/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module form.c - Receipt functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Print/form.c $ 
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#include <project.h>
#define VSFORM_C

#include <aclconio.h>
#include <stdlib.h>
#include <string.h>
#include <aclstr.h>
#include <message.h>
#include <dbmgr.h>
#include <ctype.h>

/** /#define DEBUG_VSFORM*/
#ifdef DEBUG_VSFORM
#define DEBUG_95
#endif


#include <define.h>
#include <transact.h>
#include <print.h>
#include <form.h>
#include <pform.h>
#include <gds.h>
#include <tran.h>
#include <msg.h>
#include <msgfuncs.h>
#include <batch.h>
#include <accum.h>
#include <confio.h>
#include <cst.h>
#include <bdt.h>
#include <cdt.h>
#include <hdt.h>
#include <lct.h>
#include <tblutil.h>
#include <mit.h>
#include <tct.h>
#include <pct.h>
#include <trt.h>
#include <date.h>
#include <ui.h>
#include <oper.h>
#include <spdebug.h>
#include <format.h>
#include <mht.h>
#include <rcptsegs.h>
#include <rcptcmpt.h>
#include <mamevent.h>
#include <varrec.h>

RCPT_FIELDS srRcpt;

extern unsigned char pucMAMEventData[];
/*-------------------------------------------------------------------------
    Function :    vdClearRcpt
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   04/21/99 Page_K1    Created.
--------------------------------------------------------------------------*/

void vdClearRcpt() {
    /** /pdebug(("--vdClearRcpt--"));*/

    memset(&srRcpt, 0, sizeof(RCPT_FIELDS));
}


void vdSetReceiptDateAndTime(TRANSACTION_OBJECT* pobTran) {
    char szDate[DATE_SIZE + 1];

    /*
     *      Batch Date is in MMDDYY format
     *      vdFormatDate expects date in YYMMDD
     */
    strcpy(szDate, pobTran->srBRec.szDate);
    if (strlen(szDate) != DATE_SIZE)
        vdGetDate(szDate, MMDDYY);
    strlcpy(srRcpt.szDate, &(szDate[4]), 2);
    strlcpy(srRcpt.szDate + 2, szDate, 2);
    strlcpy(srRcpt.szDate + 4, &(szDate[2]), 2);

    vdFormatDate(srRcpt.szDate);
    strcpy(srRcpt.szTime, pobTran->srBRec.szTime);
    vdFormatTime(srRcpt.szTime);
}

/*-------------------------------------------------------------------------
    Function :    vdClearFooter
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   10/30/95 Henry_G1   Created.
--------------------------------------------------------------------------*/

void vdClearFooter() {
    /** /pdebug(("--vdClearFooter--"));*/

    *srRcpt.szStatusMessage = 0;
    *srRcpt.szErrorMessage = 0;
}

/*-------------------------------------------------------------------------
    Function :    vdMakeFooter
    Description :
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   07/17/95 Henry_G1   Created.
      1   06/16/97 Matt_V1    Removed existing code since function was not 
                              utilized.  Added code pertaining to footers
                              from vdMakeHeader.
--------------------------------------------------------------------------*/

void vdMakeFooter(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--vdMakeFooter--"));*/
    //jrd one source
    #ifdef __arm
    unsigned short shlength;
    #endif
    #ifdef _TARG_68000
    unsigned int shlength;
    #endif	

    
    strcpy(srRcpt.szSpecialMessage, szGetRctFoot1());
    strcpy(srRcpt.szStatusMessage, szGetRctFoot2());
    strcpy(srRcpt.szStatus2Message, szGetRctFoot3());
    strlcpy(srRcpt.szErrorMessage, szGetRctFoot4(), TERM_ADDR_SIZE);

    if (srGDS.fExternalEvent)  /* sadiq added */ {
        shVarGetField((pucMAMEventData), RECEIPT_MSG1, (unsigned char *) srRcpt.szMultiAppMsg1, RECEIPT_HEADER_SIZE + 1, &shlength); 
        shVarGetField((pucMAMEventData), RECEIPT_MSG2, (unsigned char *) srRcpt.szMultiAppMsg2, RECEIPT_HEADER_SIZE + 1, &shlength);
    }


    if (pobTran->lnSpecialMessageIndex)     /* mb1 */
        vdGetMessageFromFile(pobTran->lnSpecialMessageIndex, srRcpt.szSpecialMessage);
}

/*-------------------------------------------------------------------------
    Function :    inPrintError
    Description : Prints a communication error, also Reprint not possible
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1   06/19/95  Henry_G1   Added obPrinter parameter.
      2   06/20/95  Henry_G1   Added szFormName parameter.
      3   07/06/95  Henry_G1   Replaced szPrnErrMsg with call to
                               inGGErrorMessage.
      4   08/09/96  Page_K1    Use host response message if fFromBuf == VS_TRUE
      5   10/19/96  Page_K1    Check Tab receipt flags, if printing on tab
                               also print header
      6   01/20/97  Page_K1    do not display Printing... if printer not enabled.
      7   07/29/97  Kevin_V1   Printer Header on ISDN Online Transactions.
      8   02/16/98  Page_K1    Add param(receipt/report) to inPrintReceiptHeader() call
      9   09/15/98  Page_K1    Use obPrinter->inType and srTCTRec.inP350ColMode to
                                determine 32 char print format
     10   02/05/99  Page_K1    Call inPrintReceiptBottom() with PRT_ERROR                                
--------------------------------------------------------------------------*/

int inPrintError(TRANSACTION_OBJECT* pobTran,long lnMsgIdx,VS_BOOL fFromBuf,PRINTER_OBJECT* pobPrinter) {
    pdebug(("--inPrintError--"));

    srRcpt.szErrorMessage[0] = 0;  
    srRcpt.szStatusMessage[0] = 0;  
    srRcpt.szSpecialMessage[0] = 0;  
    srRcpt.szStatus2Message[0] = 0;  


    if (((pobTran->srBRec.fCloseTabSameCard || pobTran->srBRec.fCloseTabNewCard) && (!fPrintCloseTab(pobTran))) || ((inGGCode() == PRE_AUTH) && (fGetOpenTabOptRec() == VS_FALSE)))
        return(VS_SUCCESS);

    if (fFromBuf == VS_TRUE)
        vdGGRespMsg(srRcpt.szErrorMessage);
    else
        vdGetMessageFromFile(lnMsgIdx, srRcpt.szErrorMessage);

    pobTran->srBRec.inPrintOption = PRT_ERROR;  
    if (inRunFormSegments(pobTran, PRINT_ERROR) != VS_SUCCESS)
        return(VS_ERR);

    pdebug(("--out inPrintError--"));

    return(VS_SUCCESS);
}

#undef VSFORM_C

